//1-防抖函数
function debounce(fn, delay) {
  let timer = null;
  let _debounce = function (e, thisArg) {
    if (timer) {
      clearTimeout(timer);
    }

    timer = setTimeout(() => {
      fn.apply(thisArg);
    }, delay);
  };

  return _debounce;
}
//2需要防抖的函数
let fetchFn = function () {
  console.log("网络请求~", this);
};

//3进行函数防抖化
let debounceFn = debounce(fetchFn, 500);

let input = document.querySelector("input");
//触发的事件
input.addEventListener("input", function (e) {
  debounceFn(e, this);
  console.log("input", this);
});
